﻿Imports System
Imports System.Web

Partial Public Class Helper
    ''' <summary>
    ''' Gets the domain section for the Host Name
    ''' www.(domain.com)
    ''' </summary>
    ''' <returns>Last 2 segments of the domain host</returns>
    Public Function Domain() As [String]
        Return Domain(HttpContext.Current.Request.Url.Host)
    End Function
    ''' <summary>
    ''' Gets the domain section for the Host Name
    ''' www.(domain.com)
    ''' </summary>
    ''' <returns>Last 2 segments of the domain host</returns>
    Public Function Domain(ByVal host As [String]) As [String]
        Dim result As [String] = host
        If result.Contains(".") Then
            Dim hostSegments As [String]() = result.Split("."c)
            Array.Reverse(hostSegments)
            Domain = (hostSegments(1) & ".") + hostSegments(0)
        End If
        Return result
    End Function
End Class